home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / linker / patch.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  781 b   |  24 lines  |  [TEXT/MPS ]

  1. (* To relocate a block of object bytecode *)
  2.  
  3. #open "reloc";;
  4. #open "symtable";;
  5.  
  6. let patch_short buff pos val =
  7.   set_nth_char buff pos (char_of_int val);
  8.   set_nth_char buff (succ pos) (char_of_int (lshift_right val 8))
  9. ;;
  10.  
  11. let patch_object buff offset =
  12.   do_list (function
  13.     Reloc_literal sc, pos ->
  14.       patch_short buff (pos + offset) (get_slot_for_literal sc)
  15.   | Reloc_getglobal id, pos ->
  16.       patch_short buff (pos + offset) (get_slot_for_variable id)
  17.   | Reloc_setglobal id, pos ->
  18.       patch_short buff (pos + offset) (get_slot_for_defined_variable id)
  19.   | Reloc_tag(id, stamp), pos ->
  20.       set_nth_char buff (pos + offset) (char_of_int (get_num_of_exn(id,stamp)))
  21.   | Reloc_primitive name, pos ->
  22.       patch_short buff (pos + offset) (get_num_of_prim name))
  23. ;;
  24.